//1、字符串去重＋计数
var str = 'aabccd'
String.prototype.countIndexOf = countIndexOf

Object.prototype.forEach=function(fn){ 
    let obj =this
    for (let key in obj){
        if(key==='forEach'){
            continue;
        }
        fn(obj[key],key,obj)
      
    }
}
Set.prototype.join = function (str) {
  let str1 = ''
  let array = []
  let obj = {}
  this.forEach((item) => {
    array.push(str.countIndexOf(item))
    str1 += item
  })
  obj.newStr = str1

  obj.oldStr = str
  obj.counts = array
  return obj
}
function countIndexOf(val) {
    let vals =this
  let count = 0
  while (vals.indexOf(val) != -1) {
    vals = vals.replace(val, '')
    count++
  }
  return count
}
//1、
function makeItOne() {
    var str  =this
   if(typeof str==='object'){
      str = str.valueOf()
   }
  return new Set(str).join(str)
}
String.prototype.makeItOne=makeItOne

//2、
String.prototype.isHuiWen=function(){
  return typeof this.valueOf()==='string'?  (this.valueOf().split('').reverse().join('') === this.valueOf() ? true : false) :-1
}
// console.log('你好世界世好你'.isHuiWen());



//3、
String.prototype.reverse=function(){
    return this.split('').reverse().join('')
}
// console.log('我是一个小肥仔'.reverse());



//4、
String.prototype.getCount=function(){
    let obj = this.makeItOne()
    console.log(obj);
    let new_obj = {}
    obj.forEach((item,key,obj)=>{
        if(key=='counts'){
            item.forEach((item1,index)=>{
              new_obj[obj.newStr[index]]=item1
            })
        }
    })
    return new_obj
}

// console.log('我我我牛牛奶奶'.getCount());


